package org.example.config;

import lombok.Data;
import org.example.util.constantUtil.ConstantUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@Data
@ConfigurationProperties(prefix = "nuowan")
public class ApiConfig {
    private String ipAddress;

    private String username;

    private String password;

    private String port;

    /**
     * 获取完整请求地址
     * @return http://address:port
     */
    public String getURL(){
        return "http://"+ipAddress+":"+port;
    }

    /**
     * 获取遥测数据地址前后缀
     */
    public String getDataApiPrefix(){
        return this.getURL()+"/api/plugins/telemetry/DEVICE/";
    }
    public String getDataApiSuffix(){
        return "/values/timeseries";
    }

    /**
     * 获取token地址
     */
    public String getTokenApi(){
        return this.getURL()+"/api/auth/login";
    }
    public String refresTokenApi(){
        return this.getURL()+"/api/auth/token";
    }

    //=====================Device Controller=====================
    /**
     * 获取设备信息地址
     */
    public String getDeviceInfosApi(){
        return this.getURL()+"/api/tenant/deviceInfos";
    }

    /**
     * customerTitle查询customerId  使用方法：URL+"?"+"customerTitle={项目号}"
     */
    public String getIdsByCustomerTitle(){
        return this.getURL()+"/api/tenant/customers";
    }

    /**
     * 获取当前用户
     */
    public String getCurrentUserApi(){
        return this.getURL()+"/api/auth/user";
    }

    /**
     * 获取用户设备地址 使用方法: PREFIX+customerId+SUFFIX+"?"+param
     */
    public String getCustomerDeviceInfosApiPrefix(){
        return this.getURL()+"/api/customer/";
    }
    public String getCustomerDeviceInfosApiSuffix(){
        return "/deviceInfos";
    }

    //=====================entity-query-controller=====================
    /**
     * 通过字段查询设备
     */
    public String entityQueryApi(){
        return this.getURL()+"/api/entitiesQuery/find";
    }

    /**
     * Mqtt broker地址
     */
    public String getMqttBroker(){
        return "tcp://"+ this.ipAddress +":1884";
    }

}
